﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace produccion.clases
{
    class CLSTABSOL
    {
        string codsol_sol, nombre_sol;
        MDOgeneral mod = new MDOgeneral();

        public string CODSOL_SOL
        {
            get { return codsol_sol; }
            set { codsol_sol = value; }
        }

        public string NOMBRE_SOL
        {
            get { return nombre_sol; }
            set { nombre_sol = value; }
        }

        public List<CLSTABSOL> listarSoluciones()
        {

            try
            {
                string query = "select codsol_sol, nombre_sol from tabsol order by nombre_sol";
                DataTable val = mod.consulta(query);
                List<CLSTABSOL> lisdan = new List<CLSTABSOL>();
                foreach (DataRow r in val.Rows)
                {
                    lisdan.Add(new CLSTABSOL
                    {
                        CODSOL_SOL = r["CODSOL_SOL"].ToString(),
                        NOMBRE_SOL = r["NOMBRE_SOL"].ToString()
                    });
                }
                return lisdan;
            }
            catch (Exception ex) { throw (ex); }
        }

        public int Insertar()
        {
            try
            {
                string query = "INSERT INTO TABSOL(CODSOL_SOL, NOMBRE_SOL) VALUES ('" + CODSOL_SOL + "','" + NOMBRE_SOL + "')";
                return mod.comando(query);
            }
            catch (Exception ex) { throw ex; }
        }

        public int Actualizar()
        {
            try
            {
                string query = "update tabsol set nombre_sol='" + NOMBRE_SOL + "' where codsol_sol='" + CODSOL_SOL + "'";
                return mod.comando(query);
            }
            catch (Exception ex) { throw ex; }
        }

        public int Eliminar()
        {
            try
            {
                string query = "delete from tabsol where codsol_sol='" + CODSOL_SOL + "'";
                return mod.comando(query);
            }
            catch (Exception ex) { throw ex; }
        }

        public DataTable Consultar()
        {
            try
            {
                string query = "select codsol_sol, nombre_sol from tabsol order by nombre_sol";
                return mod.consulta(query);
            }
            catch (Exception ex) { throw ex; }
        }

        public Boolean Existe()
        {
            try
            {
                string query = "select codsol_sol from tabsol where codsol_sol='" + CODSOL_SOL + "'";
                if (mod.consulta(query).Rows.Count > 0)
                {
                    return true;
                }
                return false;
            }
            catch (Exception ex) { throw ex; }
        }


        public DataTable consLisSol() 
        {
            try 
            {
                string query = "select TRIM(CODSOL_SOL) as CODSOL_SOL, TRIM(NOMBRE_SOL) as NOMBRE_SOL from tabsol order by NOMBRE_SOL";
                return mod.consulta(query);
            }
            catch (Exception ex) { throw ex; }
        }



    }
}
